﻿package com.wandian.util
{
	import com.wandian.data.GameData;
	import com.wandian.util.scrollBar.ScrollBarMc;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;

    public class CLZListPage extends Object
    {
        private var _arrList:Array;
        private var _arrDelete:Array;
        private var _isSelectAll:Boolean = false;
        private var _btnFrist:MovieClip;
        private var _btnEnd:MovieClip;
        private var _btnPrev:MovieClip;
        private var _btnNext:MovieClip;
        private var _txtPagingThis:TextField;
        private var _txtPagingAll:TextField;
        private var _arrInfo:Array;
        private var _nPageingThis:int = 1;
        private var _nPageingAll:int = 1;
        private var _nPage:int = 0;
        public static var UPDATE_DATA:String = "UPDATE_DATA";

        public function CLZListPage(param1:Array, param2:MovieClip, param3:MovieClip, param4:TextField = null, param5:TextField = null, param6:MovieClip = null, param7:MovieClip = null) : void
        {
            this._arrDelete = new Array();
            this._arrInfo = new Array();
            this._arrList = param1;
            this._nPage = this._arrList.length;
            this._btnFrist = param6;
            this._btnEnd = param7;
            this._btnPrev = param2;
            this._btnNext = param3;
            this._txtPagingThis = param4;
            this._txtPagingAll = param5;
            if (this._btnFrist != null)
            {
                this._btnFrist.addEventListener(MouseEvent.CLICK, this.clickLeftHandler);
            }
            if (this._btnEnd != null)
            {
                this._btnEnd.addEventListener(MouseEvent.CLICK, this.clickRightHandler);
            }
            this._btnPrev.addEventListener(MouseEvent.CLICK, this.clickLeftHandler);
            this._btnNext.addEventListener(MouseEvent.CLICK, this.clickRightHandler);
            return;
        }

        private function clickRightHandler(event:MouseEvent) : void
        {
            if (this._nPageingThis >= this._nPageingAll)
            {
                return;
            }
			this._nPageingThis++;
            this.updatePage((this._nPageingThis - 1));
            return;
        }

        private function clickLeftHandler(event:MouseEvent) : void
        {
            if (this._nPageingThis <= 1)
            {
                return;
            }
			this._nPageingThis++;
            this.updatePage((this._nPageingThis - 1));
            return;
        }

        public function setListInfo(param1:Array) : void
        {
            if (param1.length == 0)
            {
                this.removeListInfo();
                if (this._txtPagingThis != null)
                {
                }
                if (this._txtPagingAll != null)
                {
                    this._txtPagingThis.text = "1";
                    this._txtPagingAll.text = "1";
                }
                return;
            }
            this._arrInfo = param1;
            this._nPageingAll = Math.ceil(this._arrInfo.length / this._nPage);
            this._nPageingThis = 1;
            if (this._txtPagingThis != null)
            {
            }
            if (this._txtPagingAll != null)
            {
                this._txtPagingAll.text = this._nPageingAll.toString();
                this._txtPagingThis.text = this._nPageingThis.toString();
            }
            this.updatePage((this._nPageingThis - 1));
            return;
        }

        private function updatePage(param1:int = 0) : void
        {
            var mcRow:MovieClip = null;
            this.removeListInfo();
            if (this._txtPagingThis != null)
            {
                this._txtPagingThis.text = this._nPageingThis.toString();
            }
            var _loc_2:int = 0;
            var _loc_3:* = param1 * this._nPage;
            while (_loc_3 < param1 * this._nPage + this._nPage)
            {
                
                if (_loc_3 >= this._arrInfo.length)
                {
                    break;
                }
                mcRow = this._arrList[_loc_2] as MovieClip;
                mcRow.visible = true;
                mcRow.info = this._arrInfo[_loc_3];
                mcRow.dispatchEvent(new Event(UPDATE_DATA));
                _loc_2 = _loc_2 + 1;
                _loc_3 = _loc_3 + 1;
            }
            return;
        }

        private function removeListInfo() : void
        {
            var _loc_1:int = 0;
            while (_loc_1 < this._arrList.length)
            {
                
                this._arrList[_loc_1].visible = false;
                _loc_1 = _loc_1 + 1;
            }
            return;
        }

    }
}
